From 100c9c143006dd3c615f0d95a2d80ec542a484fc Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Tue, 26 Jan 2021 11:55:59 -0700 Subject: [PATCH] cleanup CMakeLists.txt a bit. (#669) add support for cmake, ninja to Docker images. get git to ignore various generated files. --- .gitignore | 14 +++++---- CMakeLists.txt | 49 ++++++++++++++------------------ gui/.gitignore | 1 + gui/CMakeLists.txt | 64 ++++++++++++++++-------------------------- tools/Dockerfile | 2 ++ tools/Dockerfile_focal | 2 ++ tools/Dockerfile_qtio | 2 ++ 7 files changed, 61 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index b75414fef..bf6fddde4 100644 --- a/.gitignore +++ b/.gitignore @@ -14,23 +14,27 @@ /gpsbabel.html /gpsbabel.pdf /Makefile -/.qmake.cache -/.qmake.stash +.qmake.cache +.qmake.stash /GPSBabel /*.gcda /*.gcno /*.gcov *.o +.ninja_deps +.ninja_log +build.ninja +rules.ninja +cmake_install.cmake +CMakeCache.txt +CMakeFiles/ /GPSBabel[0-9]*.[0-9]*.[0-9]*/ /GPSBabel[0-9]*.[0-9]*.[0-9]*.tar.bz2 -/Makefile /makelinuxdist.sh /objects/ /release/ *.swp /tmp/ -/Makefile -/Makefile /mkcapabilities /gpsbabel.rc /autogen/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 66dd328f4..3654531e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,27 +5,21 @@ # tested against MSVC 2017 which included 3.11.* 2018/07/05 cmake_minimum_required(VERSION 3.5.1) -project(gpsbabel) +project(gpsbabel LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED True) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) # Find the Qt5Core library find_package(Qt5 COMPONENTS Core REQUIRED) -message("Qt5Core_VERSION String describing the version of the module: \"${Qt5Core_VERSION}\"") -message("Qt5Core_LIBRARIES List of libraries for use with the target_link_libraries command: \"${Qt5Core_LIBRARIES}\"") -message("Qt5Core_INCLUDE_DIRS List of directories for use with the include_directories command: \"${Qt5Core_INCLUDE_DIRS}\"") -message("Qt5Core_DEFINITIONS List of definitions for use with add_definitions: \"${Qt5Core_DEFINITIONS}\"") -message("Qt5Core_COMPILE_DEFINITIONS List of definitions for use with the COMPILE_DEFINITIONS target property: \"${Qt5Core_COMPILE_DEFINITIONS}\"") -message("Qt5Core_FOUND Boolean describing whether the module was found successfully: \"${Qt5Core_FOUND}\"") -message("Qt5Core_EXECUTABLE_COMPILE_FLAGS String of flags to be used when building executables: \"${Qt5Core_EXECUTABLE_COMPILE_FLAGS}\"") -if (${Qt5Core_VERSION} VERSION_LESS 5.9) +if(${Qt5Core_VERSION} VERSION_LESS 5.9) message(FATAL_ERROR "Qt version ${Qt5Core_VERSION} found, but version 5.9 or newer is required.") +else() + message(STATUS "Using Qt5 version ${Qt5Core_VERSION}") endif() -include_directories(AFTER SYSTEM ${Qt5Core_INCLUDE_DIRS}) -add_definitions(${Qt5Core_DEFINITIONS}) set(MINIMAL_FMTS magproto.cc explorist_ini.cc gpx.cc geo.cc mapsend.cc garmin.cc @@ -82,7 +76,7 @@ set(ZLIB set(JEEPS jeeps/gpsapp.cc jeeps/gpscom.cc - jeeps/gpsmath.cc jeeps/gpsmem.cc + jeeps/gpsmath.cc jeeps/gpsmem.cc jeeps/gpsprot.cc jeeps/gpsread.cc jeeps/gpsdevice.cc jeeps/gpsdevice_ser.cc jeeps/gpsdevice_usb.cc jeeps/gpsrqst.cc jeeps/gpssend.cc jeeps/gpsserial.cc jeeps/jgpsutil.cc @@ -98,7 +92,7 @@ set(SUPPORT gbfile.cc parse.cc session.cc main.cc globals.cc src/core/textstream.cc src/core/usasciicodec.cc - src/core/xmlstreamwriter.cc + src/core/xmlstreamwriter.cc ) set(HEADERS @@ -197,15 +191,15 @@ set(HEADERS ${HEADERS} ${FILTER_HEADERS}) include_directories(AFTER zlib) -INCLUDE (CheckIncludeFile) +include(CheckIncludeFile) if(UNIX) # this is used by zlib - CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) + check_include_file("unistd.h" HAVE_UNISTD_H) if(${HAVE_UNISTD_H}) add_definitions(-DHAVE_UNISTD_H) endif() # this is used by zlib - CHECK_INCLUDE_FILE("stdarg.h" HAVE_STDARG_H) + check_include_file("stdarg.h" HAVE_STDARG_H) if(${HAVE_STDARG_H}) add_definitions(-DHAVE_STDARG_H) endif() @@ -235,11 +229,11 @@ if(MSVC) add_compile_options(/MP -wd4100 -wd4267) endif() -if (UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE) set(LIBS ${LIBS} usb-1.0) endif() -if (APPLE) +if(APPLE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lobjc -framework IOKit -framework CoreFoundation") include_directories(AFTER mac/libusb mac/libusb/Xcode) set(SOURCES ${SOURCES} @@ -277,17 +271,16 @@ add_definitions(-DSHAPELIB_ENABLED) add_definitions(-DCSVFMTS_ENABLED) add_executable(gpsbabel ${SOURCES} ${HEADERS}) -target_link_libraries(gpsbabel ${Qt5Core_LIBRARIES} ${LIBS}) +target_link_libraries(gpsbabel Qt5::Core ${LIBS}) -message("Sources are:") -message("${SOURCES}") -message("Headers are:") -message("${HEADERS}") -message("Defines are:") -get_directory_property( DirDefs COMPILE_DEFINITIONS) -message("${DirDefs}") -message("Libs are:") -message("${LIBS}") +message(STATUS "Sources are: \"${SOURCES}\"") +message(STATUS "Headers are: \"${HEADERS}\"") +get_directory_property(DirDefs COMPILE_DEFINITIONS) +message(STATUS "Defines are: \"${DirDefs}\"") +get_target_property(LnkLibs gpsbabel LINK_LIBRARIES) +message(STATUS "Libs are: \"${LnkLibs}\"") +get_directory_property(IncDirs INCLUDE_DIRECTORIES) +message(STATUS "Include Directores are: \"${IncDirs}\"") if(UNIX) # the tests only work if the pwd is top level source dir due to the file name getting embedded in the file nonexistent.err. diff --git a/gui/.gitignore b/gui/.gitignore index 85ff478e1..c98deaa4b 100644 --- a/gui/.gitignore +++ b/gui/.gitignore @@ -2,6 +2,7 @@ /GPSBabel[0-9]*.[0-9]*.[0-9]*.tar.bz2 /GPSBabelFE/ /GPSBabelFE.app/ +/gpsbabelfe_autogen/ /Makefile /objects/ /tmp/ diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index fd91b82f2..9fd4ee063 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -5,9 +5,10 @@ # tested against MSVC 2017 which included 3.11.* 2018/07/05 cmake_minimum_required(VERSION 3.5.1) -project(gpsbabelfe) +project(gpsbabelfe LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED True) # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -19,56 +20,39 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) # Find the Qt5Core library -find_package(Qt5 COMPONENTS Core Gui Network Xml REQUIRED) -#message("Qt5Core_VERSION String describing the version of the module: \"${Qt5Core_VERSION}\"") -#message("Qt5Core_LIBRARIES List of libraries for use with the target_link_libraries command: \"${Qt5Core_LIBRARIES}\"") -#message("Qt5Core_INCLUDE_DIRS List of directories for use with the include_directories command: \"${Qt5Core_INCLUDE_DIRS}\"") -#message("Qt5Core_DEFINITIONS List of definitions for use with add_definitions: \"${Qt5Core_DEFINITIONS}\"") -#message("Qt5Core_COMPILE_DEFINITIONS List of definitions for use with the COMPILE_DEFINITIONS target property: \"${Qt5Core_COMPILE_DEFINITIONS}\"") -#message("Qt5Core_FOUND Boolean describing whether the module was found successfully: \"${Qt5Core_FOUND}\"") -#message("Qt5Core_EXECUTABLE_COMPILE_FLAGS String of flags to be used when building executables: \"${Qt5Core_EXECUTABLE_COMPILE_FLAGS}\"") -if (${Qt5Core_VERSION} VERSION_LESS 5.9) +find_package(Qt5 COMPONENTS Core Gui Network Widgets Xml REQUIRED) +list(APPEND QT_LIBRARIES Qt5::Core Qt5::Gui Qt5::Network Qt5::Widgets Qt5::Xml) +if(${Qt5Core_VERSION} VERSION_LESS 5.9) message(FATAL_ERROR "Qt version ${Qt5Core_VERSION} found, but version 5.9 or newer is required.") +else() + message(STATUS "Using Qt5 version ${Qt5Core_VERSION}") endif() # hard code webengine instead of webkit for now find_package(Qt5 COMPONENTS WebEngineWidgets WebChannel REQUIRED) +list(APPEND QT_LIBRARIES Qt5::WebEngineWidgets Qt5::WebChannel) +add_definitions(-DHAVE_WEBENGINE) -set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS} ${Qt5WebEngineWidgets_INCLUDE_DIRS} ${Qt5WebChannel_INCLUDE_DIRS}) -list(REMOVE_DUPLICATES QT_INCLUDE_DIRS) -message("QT INCLUDE DIRS: \"${QT_INCLUDE_DIRS}\"\n") - -set(QT_DEFINITIONS ${Qt5Core_DEFINITIONS} ${QT5Gui_DEFINITIONS} ${Qt5Network_DEFINITIONS} ${Qt5Xml_DEFINITIONS} ${Qt5WebEngineWidgets_DEFINITIONS} ${Qt5WwebChannel_DEFINITIONS}) -list(REMOVE_DUPLICATES QT_DEFINITIONS) -message("QT DEFS: \"${QT_DEFINITIONS}\"\n") - -set(QT_LIBRARIES ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Network_LIBRARIES} ${Qt5Xml_LIBRARIES} ${Qt5WebEngineWidgets_LIBRARIES} ${Qt5WebChannel_LIBRARIES}) -#list(REMOVE_DUPLICATES QT_LIBRARIES) -message("QT LIBS: \"${QT_LIBRARIES}\"\n") - -include_directories(AFTER SYSTEM ${QT_INCLUDE_DIRS}) -add_definitions(${QT_DEFINITIONS} -DHAVE_WEBENGINE) - -if (APPLE) +if(APPLE) find_library(IOKIT_LIBRARIES IOKit) find_library(COREFOUNDATION_LIBRARIES CoreFoundation) endif() -if (UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE) find_package(PkgConfig REQUIRED) pkg_check_modules(LIBUDEV libudev) - if (${LIBUDEV_FOUND}) + if(${LIBUDEV_FOUND}) add_definitions(-DHAVE_UDEV) endif() endif() set(RESOURCES app.qrc) -if (WIN32) +if(WIN32) set(RESOURCES ${RESOURCES} app.rc) endif() -if (UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE) set(TARGET gpsbabelfe) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY GPSBabelFE) else() @@ -115,11 +99,11 @@ set(SOURCES version_mismatch.cc ) -if (UNIX AND NOT APPLE) +if(UNIX AND NOT APPLE) set(SOURCES ${SOURCES} serial_unix.cc) -elseif (APPLE) +elseif(APPLE) set(SOURCES ${SOURCES} serial_mac.cc) -elseif (WIN32) +elseif(WIN32) set(SOURCES ${SOURCES} serial_win.cc) endif() @@ -147,7 +131,7 @@ set(HEADERS version_mismatch.h ) -if (APPLE) +if(APPLE) set(MACOSX_BUNDLE_ICON_FILE appicon.icns) set(ICON_FILE images/${MACOSX_BUNDLE_ICON_FILE}) set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) @@ -167,13 +151,13 @@ set(LIBS ${QT_LIBRARIES} ${LIBUDEV_LIBRARIES} ${IOKIT_LIBRARIES} ${COREFOUNDATIO list(REMOVE_DUPLICATES LIBS) target_link_libraries(${TARGET} ${LIBS}) -message("Sources are: \"${SOURCES}\"\n") -message("Headers are: \"${HEADERS}\"\n") +message(STATUS "Sources are: \"${SOURCES}\"") +message(STATUS "Headers are: \"${HEADERS}\"") get_directory_property(DirDefs COMPILE_DEFINITIONS) -message("Defines are: \"${DirDefs}\"\n") +message(STATUS "Defines are: \"${DirDefs}\"") get_target_property(LnkLibs ${TARGET} LINK_LIBRARIES) -message("Libs are: \"${LnkLibs}\"\n") +message(STATUS "Libs are: \"${LnkLibs}\"") get_directory_property(IncDirs INCLUDE_DIRECTORIES) -message("Include Directores are: \"${IncDirs}\"\n") +message(STATUS "Include Directores are: \"${IncDirs}\"") -add_custom_target(package COMMAND ./package_app DEPENDS ${TARGET}) +add_custom_target(package_app COMMAND ./package_app DEPENDS ${TARGET}) diff --git a/tools/Dockerfile b/tools/Dockerfile index 7198937df..7a3a041d8 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -29,6 +29,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ expat \ libxml2-utils \ bear \ + cmake \ + ninja-build \ && rm -rf /var/lib/apt/lists/* # alternative compiler diff --git a/tools/Dockerfile_focal b/tools/Dockerfile_focal index 77e1588cf..85d618743 100644 --- a/tools/Dockerfile_focal +++ b/tools/Dockerfile_focal @@ -26,6 +26,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ expat \ libxml2-utils \ bear \ + cmake \ + ninja-build \ clazy \ && rm -rf /var/lib/apt/lists/* diff --git a/tools/Dockerfile_qtio b/tools/Dockerfile_qtio index 15b8e9712..a06f758e2 100644 --- a/tools/Dockerfile_qtio +++ b/tools/Dockerfile_qtio @@ -63,6 +63,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ expat \ libxml2-utils \ bear \ + cmake \ + ninja-build \ && rm -rf /var/lib/apt/lists/* # alternative compiler -- 2.30.2